package com.kaishengit.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.entity.TaskEmployee;
import com.kaishengit.service.GoalService;
import com.kaishengit.service.TaskEmployeeService;
import com.kaishengit.service.TaskService;
import com.kaishengit.util.StringUtil;
import com.kaishengit.util.db.Page;

public class Task extends HttpServlet {

	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = request.getParameter("id");
		String p = request.getParameter("p");
		
		int pageNum = 1;
		if(StringUtil.isNotEmpty(p)) {
			try {
				pageNum = Integer.parseInt(p);
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
		}
		
		com.kaishengit.entity.Goal goal = new GoalService().findById(id);
		
		List<com.kaishengit.entity.TaskEmployee> list = new TaskEmployeeService().findByGoalId(id);
		request.setAttribute("list", list);
		double goalrate = 0;
		for(int i=0;i<list.size();i++){
			goalrate += (list.get(i)).getTaskrate();
		}
		goal.setRate(goalrate);
		HttpSession session = request.getSession();
		session.setAttribute("goal", goal);
		request.getRequestDispatcher("WEB-INF/views/task.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

}
